package com.op.teachingliteapp.fragment.resourcedetails;

import java.util.ArrayList;


import android.app.Fragment;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import android.widget.Toast;
import com.op.teachingliteapp.R;
import com.op.teachingliteapp.fragment.PPTShowFragment;
import com.op.teachingliteapp.sender.*;
import com.op.teachingliteapp.sender.Runtime;


/*
 * //这个fragment写选择列表
 */
public class ResourceDetailsFragment extends Fragment {

    final int itemId = 1;
    private ListView mListView;
    ArrayList<ResourceDetailsDataProvider> ppt_list = new ArrayList<ResourceDetailsDataProvider>();
    private ResourceDetailsAdapter mAdapter;
    private boolean isShowDelete = false;
    private int index;
    private String description;
    private static final String sdcardPath = Environment.getExternalStorageDirectory().getPath();
    private static String Location = sdcardPath + "/DEMO/";


    @Override
    public void onDestroy() {
        super.onDestroy();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_resource_details_ppt,
                container, false);
        String url = Environment.getExternalStorageDirectory().getPath();

        String url2 = Environment.getExternalStorageDirectory().getPath();
        mListView = (ListView) root.findViewById(R.id.ppt_listView);
        description = getString(R.string.ppt_list_dex);
        ppt_list.add(new ResourceDetailsDataProvider("第1章 Java概述", description,
                Location + "java_1.pdf", R.drawable.ppt));
        ppt_list.add(new ResourceDetailsDataProvider("第2章 Java语言基础",
                description, Location + "java_2.pdf", R.drawable.ppt));
        ppt_list.add(new ResourceDetailsDataProvider("第3章 类的封装、继承和多态",
                description, Location + "java_3.pdf", R.drawable.ppt));
        ppt_list.add(new ResourceDetailsDataProvider("第4章 接口、内部类和包",
                description, Location + "java_4.pdf", R.drawable.ppt));
        ppt_list.add(new ResourceDetailsDataProvider("第5章 异常处理",
                description, Location + "java_5.pdf", R.drawable.ppt));
        ppt_list.add(new ResourceDetailsDataProvider("第6章 图形用户界面",
                description, Location + "java_6.pdf", R.drawable.ppt));
        ppt_list.add(new ResourceDetailsDataProvider("第7章 多线程",
                description, Location + "java_7.pdf", R.drawable.ppt));

        mAdapter = new ResourceDetailsAdapter(getActivity(), ppt_list);
        mListView.setAdapter(mAdapter);

        mListView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                if (Runtime.ip==null) {
                    Toast.makeText(getActivity().getApplicationContext(),"没有选择接收端",Toast.LENGTH_LONG).show();
                    return;
                }


                if (position != ppt_list.size() - 1) {
                    ResourceDetailsDataProvider resourceDetailsDataProvider = mAdapter.getItem(position);
                    String url = resourceDetailsDataProvider.getUrl();
                    PPTShowFragment pptShow = new PPTShowFragment();
                    Bundle bundle = new Bundle();
                    bundle.putString("url", url);
                    pptShow.setArguments(bundle);

                    getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.main_show2, pptShow).commit();


                }


            }


        });
        return root;
    }

}
